﻿/*

filipesilvestrim - An open-source ActionScript 3.0 repository of codes for Game Developers 

http://code.google.com/p/filipesilvestrim/

Copyright (c) 2009 Filipe Ghesla Silvestrim, All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

package com.filipesilvestrim.ds
{
	import flash.utils.Dictionary;

	public class Array2
	{
		// ___________________________________________________________________ CONSTANTS
		
		// ___________________________________________________________________ CLASS PROPERTIES
		private var _w 		: int		= -1;
		private var _h		: int		= -1;
		private var _adapt	: Boolean	= true;
		
		// ___________________________________________________________________ INSTANCE PROPERTIES
		private var _aw	 	: Array;
		private var _ah	 	: Array;
		
		// ___________________________________________________________________ GETTERS AND SETTERS
		public function get width () 	: uint				{ return _w; }
		public function get height () 	: uint				{ return _h; }
		
		// ___________________________________________________________________ CONSTRUCTOR
		
		public function Array2 (w : int = -1, h : int = -1, adapt : Boolean = false) 
		{
			_w 	= w;
			_h	= h;
			
			_aw		= new Array();
			_ah		= new Array();
			
			init();
		}
		
		// ___________________________________________________________________ PUBLIC METHODS
		public function get () : *
		{
			
		}
		
		public function set () : void
		{
			
		}
		
		public function fill ( value : * ) : void
		{
			
			
		}
		
		public function debug () : String
		{
			var str : String;
			
			for ( var w : int = 0; w < _w; w++)
				for ( var h : int = 0; h < _h; h++)
					str = str + ","; if(h == _h) str = str + "\n";
			
			return "[Array2] :: " + str;
		}
		
		private function init () : void
		{
			for ( var w : int = 0; w < _w; w++)
				for ( var h : int = 0; h < _h; h++)
					_aw[w] = _ah[w] = new Array();
			
			fill(null);
		}
		
		private function resize ( isAdaptative : Boolean = false ) : void
		{
			
		}
		
		/*
		public function add(line : int, column : int, value : *) : void
		{
			_count++;
			
			_width	= (column+1 > _width ? column+1 : _width);
			_height	= (line+1 > _height ? line+1 : _height);
			
			_matrix[line + "|" + column] = value;
		}
		
		public function get(line : int, column : int) : *
		{
			return _matrix[line + "|" + column];
		}
		
		public function remove (line : int, column : int) : void
		{
			_count--;
			_matrix[line + "|" + column] = null;
		}
		
		public function removeAll () : void
		{
			for ( var name : String in _matrix) 
				_matrix[name] = null;
				
			_count = 0;
		}
		
		public function populate ( arr : Array, columns : int = -1) : void
		{
			var col : int = columns;
			
			if(col == -1 && _width > -1)
				col = _width;
			else
				throw new Error("Array2 ERROR :: you can't populate if there is no one column defined");
			
			for (var i : int = 0; i < arr.length; i++)
				add(int(i/col), (i%col), arr[i]);
		}
		
		public function fill (value : String) : void				
		{
			for ( var line : int = 0; line < _height; line++)
				for ( var column : int = 0; column < _width; column++)
					add(line, column, value);
		}
		
		public function returnArray (withPropertie : String = null) : Array				
		{
//			trace(">>>> " + _width + " | " + _height);
			
			var arr : Array = new Array();
			
			for ( var line : int = 0; line < _height; line++)
			for ( var column : int = 0; column < _width; column++)
			{
//				trace(line + "|" + column + " >>> " + _matrix[line + "|" + column])
				
				if(_matrix[line + "|" + column] != undefined)
				{
					if(withPropertie != null)
						arr.push(_matrix[line + "|" + column][withPropertie]);
					else
						arr.push(_matrix[line + "|" + column]);
				}
			}
					
			return arr; 
		}
		*/
		// ___________________________________________________________________ PRIVATE METHODS
		
		// ___________________________________________________________________ EVENTS
	}
}

